<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS3-属性选择器</title>
  <style>
    div {
      width: 100px;
      height: 100px;
    }

    /* 属性选择器：选取标签带有某些特殊属性的选择器 */
    /* 选择所有带有class属性的div */
    div[class] {
      background-color: cadetblue;
    }

    /* 选择带有class属性=d2的div */
    div[class=d2] {
      background-color: lightblue;
    }

    /* 选择带有class属性=d开头的div */
    /* 
    div[class^=d] {
      background-color: lightcoral;
    }
    */

    /* 选择带有class属性=d结尾的div */
    /* 
    div[class$=d] {
      background-color: lightsalmon;
    }
    */

    /* 选择带有class属性包含d的div */
    div[class*=d] {
      background-color: lightseagreen;
    }

    div[id] {
      border: 3px solid lightcoral;
    }
  </style>
</head>
<body>
  <div class="d1">DIV1</div>
  <div class="d2">DIV2</div>
  <div id="d">DIV3</div>
  <div>DIV4</div>
  <div class="d3">DIV5</div>
  <div class="6d">DIV6</div>
</body>
</html>